package com.example.yuejian.Activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yuejian.Bean.RegBean;
import com.example.yuejian.Model.RegModel;
import com.example.yuejian.R;
import com.example.yuejian.RetrofitListener;

public class RegActivity extends Activity implements RetrofitListener<RegBean> {
    private EditText username,password,userphone;
    private Button register_button;
    private TextView text_back;
    private Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reg);
        initView();

    }
   public void initView(){
       username=(EditText)findViewById(R.id.edit_unme);
       userphone=(EditText)findViewById(R.id.edit_phone);
       password=(EditText)findViewById(R.id.edit_phone);
       register_button=(Button)findViewById(R.id.button_Reg);
       text_back=(TextView)findViewById(R.id.textView_back);
       register_button.setOnClickListener( new View.OnClickListener() {
           @Override
           public void onClick(View v) {

               Reg();
           }
       });
       text_back.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               intent=new Intent();
               intent.setClass(RegActivity.this,LoginActivity.class);
               startActivityForResult(intent,1);
           }
       });



   }


    public  void Reg(){
        RegModel regModel=new RegModel();
        regModel.userReg(username.getText().toString(),password.getText().toString(),userphone.getText().toString(), this);
    }
    @Override
    public void onSuccess(RegBean success , int flag)
    {


        if("0".equals(success.getSuccess()))
        {
            Toast.makeText(RegActivity.this,success.getContent(),Toast.LENGTH_SHORT).show();
        }else if ("2".equals(success.getSuccess()))
        {

            intent = new Intent(RegActivity.this,MainActivity.class);
            startActivity(intent);
            Toast.makeText(RegActivity.this,"注册成功",Toast.LENGTH_SHORT).show();

        }else if("1".equals(success.getSuccess()))
        {

            Toast.makeText(RegActivity.this,success.getContent(),Toast.LENGTH_SHORT).show();
        }
    }
    @Override
    public void onFail() {
    }


}
